package com.tencent.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tencent.entity.Order;
import com.tencent.entity.Pagination;
import com.tencent.entity.SetMeal;
import com.tencent.mapper.ShowOrderMapper;
import com.tencent.service.OrderMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Date;
import java.util.List;

/**
 * @author: @date: 2022/8/15 11:25
 * @description:
 */
@Service
public class OrderMemberServiceImpl implements OrderMemberService {

    @Autowired
    private ShowOrderMapper showOrder;


    @Override
    public List<Order> getTest(String str) {
        return showOrder.findByName2(str);
    }

    @Override
    public int deleteByIdInfo(int id) {
        int count = showOrder.deleteByIdInfo(id);
        return count;
    }

    @Override
    public int updateByIdInfo(int id) {
        int updateByIdInfo = showOrder.updateByIdInfo(id);
        return updateByIdInfo;
    }

    @Override
//    @Transactional
    public int addInfo(@RequestBody Order order) {

        int count2 = showOrder.addInfo2(order);
        int id = order.getId();
        order.setMemberId(id);
        int count1 = showOrder.addInfo1(order);
        Date date = order.getOrderDate();
        int a = showOrder.selectSetByDate(date);
        if (a == 0) {
            int b = showOrder.createSet(date);
        }
        if (count1 > 0 && count2 > 0) {
            return 1;
        }
        return 0;
    }

    @Override
    public List<SetMeal> findAll() {
        return showOrder.findAll();
    }


    @Override
    public PageInfo<Order> selectOrderByName(Pagination pagination) {
        PageHelper.startPage(pagination.getCurrentPage(), pagination.getPageSize());
        List<Order> list = showOrder.findByName(pagination.getQueryString());

        return new PageInfo<>(list);
    }
}